<div id="printbox"></div>
<div class="table-action">
<{button type="button" id="btn_print_current" onclick="pt.doPrintCurrent()" label=$___express="打印"|t:'express' }>
</div>

<script>

/*添加SWF到页面*/
var fpath = "<{$env.app.res_url}>/images/printmode.swf?<{$smarty.now}>"; //载入容器SWF //printload
var fid = "printmode"; // 设置flash id
this.swf = new Swiff(fpath, {
            width:  1024,
            height: 600,
            id:fid,
            container: $('printbox'),
            params:{
                wMode:'opaque'
            }
        });


/*var Print = new Class({
    Extends:Options,
    initialize:function(){}
});*/
var Print = function(id){this.initialize(id)};
Print.prototype = {
    templateId:'<{$tmpl.prt_tmpl_id}>',
    initialize: function(id){
        this.flash = $(id);
    },
    addBackground:function(){
        var url = 'index.php?app=express&ctl=admin_delivery_printer&act=upload_bg';
        if(this.templateId){
            url += '&p[0]='+this.templateId;
        }
        this.dlg=new Dialog(url,{model:true,title:'上传物流单据（快递单）扫描图',height:340,width:480});
    },
	setBgID:function(tmp_bg){
		this.tmp_bg = tmp_bg;
	},
    /*添加背景图片 打开选择框*/
    replaceBackground :function(url){
        this.flash["pt.replaceBackground"](url);
    },
    /*打印全部*/
    doPrintAll:function(){
        this.flash["pt.doPrintAll"]();
    },
    /*打印当前*/
    doPrintCurrent:function(){
        this.flash["pt.doPrintCurrent"]();
    },
    /*打印选段*/
    doPrintSelected:function(){
        this.flash["pt.doPrintSelected"]();
    },
    /*改变舞台尺寸*/
    resizeCanvas:function(obj){
        this.flash.style.width = obj.width + "px";
        this.flash.style.height = obj.height + "px";
    },
    /*保存模板*/
    saveTemplate: function(temp){
        if(!temp.name){
            alert('<{t}>请填写单据名称<{/t}>');
            return;
        }
        if(!temp.size.width){
            alert('<{t}>请填写快递单模版宽度<{/t}>');
            return;
        }else if(temp.size.width < 0 || temp.size.width >255){
            alert('<{t}>模板宽度只能是0-255数值范围之内<{/t}>');
            return;
        }
        if(!temp.size.height){
            alert('<{t}>请填写快递单模版高度<{/t}>');
            return;
        }else if(temp.size.height < 0 || temp.size.height > 255){
            alert('<{t}>模板高度只能是0-255数值范围之内<{/t}>');
            return;
        }
        if(!temp.offset.x || temp.offset.x < -127 || temp.offset.x > 128){
            temp.offset.x = 0;
            alert('<{t}>模板横向偏移数只能"-127 和 128"数值范围之内<{/t}>');
            return;
        }else if(isNaN(temp.offset.x)){
            alert('<{t}>模板横向偏移数只能是数字<{/t}>');
            return;
        }
        if(!temp.offset.y || temp.offset.y < -127 || temp.offset.y > 128){
            temp.offset.y = 0;
            alert('<{t}>模板纵向偏移数只能"-127 和 128"数值范围之内<{/t}>');
            return;
        }else if(isNaN(temp.offset.y)){
            alert('<{t}>模板纵向偏移数只能是数字<{/t}>');
            return;
        }
		temp.prt_tmpl_id = '<{$tmpl.prt_tmpl_id}>';
		temp.tmp_bg = this.tmp_bg;
        W.page('index.php?app=express&ctl=admin_delivery_printer&act=<{$save_action}>',{method:'post',data:temp});
    },
    /*#####################
    *   set || get
    **####################*/
    /* 设置初始打印数据*/
    setPrintData    :   function(obj){
        this.printData = obj
    },
    /*返回初始打印数据*/
    getPrintData    :   function(){
        return this.printData;
    },

    /*设置打印模板列表*/
    setTemplateData :   function(obj){
        this.templateData = obj;
    },
    /*返回打印模板列表*/
    getTemplateData :   function(){
        return this.templateData;
    },

    /*设置测试模板数据*/
    setTestTemplateData :   function(obj){
        this.testTemplateData = obj;
    },
    /*返回测试模板数据*/
    getTestTemplateData :   function(){
        return this.testTemplateData;
    }
}

/*打印程序AS+JS交互接口*/
var pt = new Print(fid);

var templateData = <{$templateData}>;

/*设置打印模板列表*/
pt.setTemplateData(templateData);

var testTemplateData = [<{$testTemplateData}>];
/*设置测试模板数据*/
pt.setTestTemplateData(testTemplateData);
</script>
